<html>
<head><meta charset="utf-8"><title>List backwards-compatibility footguns · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/List.20backwards-compatibility.20footguns.html">List backwards-compatibility footguns</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="185290265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/List%20backwards-compatibility%20footguns/near/185290265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Kalbertodt <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/List.20backwards-compatibility.20footguns.html#185290265">(Jan 10 2020 at 08:17)</a>:</h4>
<p>Recently I was involved in quite a few std related PRs and ideas that turned out to be difficult to implement because of backwards compatibility. For example, my own "impl <code>IntoIterator</code> for arrays" and this <a href="https://github.com/rust-lang/rust/pull/66504" target="_blank" title="https://github.com/rust-lang/rust/pull/66504">impl <code>Add&lt;char&gt; for String&gt;</code></a> one (btw I agree with closing it). It feels like only few (if any) people were really aware that those future changes would be hard or impossible to do when designing the current API. </p>
<p>So I thought about creating some kind of list with examples of backwards compatibility footguns for people designing an API. This can be used by everyone but would mainly be useful for high-stakes APIs like libstd. </p>
<p>Any opinions? Is there something like this already? If not and you think it could be useful, I would take a stab at writing a list soon.</p>



<a name="185291436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/List%20backwards-compatibility%20footguns/near/185291436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/List.20backwards-compatibility.20footguns.html#185291436">(Jan 10 2020 at 08:43)</a>:</h4>
<p><span class="user-mention" data-user-id="118772">@Lukas Kalbertodt</span> would it be possible to just add tests to libstd to cover those cases ?</p>



<a name="185291518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/List%20backwards-compatibility%20footguns/near/185291518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/List.20backwards-compatibility.20footguns.html#185291518">(Jan 10 2020 at 08:44)</a>:</h4>
<p>(I think that documenting backward-compat footguns is something worth doing, but ideally we would do so in such a way that backward-incompatible changes break libstd test suite)</p>



<a name="185296125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/List%20backwards-compatibility%20footguns/near/185296125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Kalbertodt <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/List.20backwards-compatibility.20footguns.html#185296125">(Jan 10 2020 at 10:01)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> Interesting idea. So those can't be simple unit tests, right? I think writing automated tests for this is really really hard. But surely worth investigating.</p>



<a name="185296157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/List%20backwards-compatibility%20footguns/near/185296157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/List.20backwards-compatibility.20footguns.html#185296157">(Jan 10 2020 at 10:02)</a>:</h4>
<p>We have run-pass, run-fail, compile-pass, and compile-fail tests in rustc.</p>



<a name="185296221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/List%20backwards-compatibility%20footguns/near/185296221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/List.20backwards-compatibility.20footguns.html#185296221">(Jan 10 2020 at 10:02)</a>:</h4>
<p>So if we have a pattern that should compile and pass some assert succesfully, you add a run-pass test, and if the pattern should not compile, you add a compile-fail test.</p>



<a name="185296266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/List%20backwards-compatibility%20footguns/near/185296266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/List.20backwards-compatibility.20footguns.html#185296266">(Jan 10 2020 at 10:03)</a>:</h4>
<p>Right now most of these are all in the src/test directory, and I would be fine with adding libstd tests there if that simplifies things, e.g., for compile-fail tests at least.</p>



<a name="185296335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/List%20backwards-compatibility%20footguns/near/185296335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/List.20backwards-compatibility.20footguns.html#185296335">(Jan 10 2020 at 10:04)</a>:</h4>
<p>If this becomes a common thing it shouldn't be too hard to set up compile-fail tests for libstd or liballoc themselves in their directories.</p>



<a name="185306865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/List%20backwards-compatibility%20footguns/near/185306865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/List.20backwards-compatibility.20footguns.html#185306865">(Jan 10 2020 at 12:48)</a>:</h4>
<p>no we really don't need separate directories</p>



<a name="185306875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/List%20backwards-compatibility%20footguns/near/185306875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/List.20backwards-compatibility.20footguns.html#185306875">(Jan 10 2020 at 12:48)</a>:</h4>
<p>like, these tests can just go in <code>src/test/ui/std/foo.rs</code></p>



<a name="185325445"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/List%20backwards-compatibility%20footguns/near/185325445" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Kalbertodt <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/List.20backwards-compatibility.20footguns.html#185325445">(Jan 10 2020 at 16:26)</a>:</h4>
<p>I think I didn't properly explain myself. I am talking about general patterns. Like take the <code>Add&lt;char&gt; for String</code> problem. The root problem here is that when resolving a trait method call and there is only one implementation, the compiler tries eagerly to coerce the argument expression into the expected type. Type inference is also working in that case. So adding a second impl means that those eager coercion and type inferences are not made anymore. This can lead to breakage. Just check the link above for more information.</p>
<p>We can of course add specific tests for <code>String</code>, but I am talking about the general pattern here. The problem was that we weren't aware of that problem when designing the <code>Add</code> impls for <code>String</code>, so we couldn't have added a test either. So we would need a lint that checks all types/impls of the public API for these kinds of problems. And that's not a simple test.</p>



<a name="185325485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/List%20backwards-compatibility%20footguns/near/185325485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Kalbertodt <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/List.20backwards-compatibility.20footguns.html#185325485">(Jan 10 2020 at 16:27)</a>:</h4>
<p>But maybe I should just start creating the list, as we can discuss more properly then ^_^</p>



<a name="185372354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/List%20backwards-compatibility%20footguns/near/185372354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/List.20backwards-compatibility.20footguns.html#185372354">(Jan 11 2020 at 03:46)</a>:</h4>
<p><span class="user-mention" data-user-id="118772">@Lukas Kalbertodt</span> This is the kind of thing we started <a href="https://github.com/rust-lang/rust-forge/blob/master/src/libs/maintaining-std.md" target="_blank" title="https://github.com/rust-lang/rust-forge/blob/master/src/libs/maintaining-std.md">the libs forge docs</a> for <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>